package com.chaos.framework.model.enums;

import lombok.Getter;

/**
 * @author Jacky
 */

@Getter
public enum ResultEnum {
    //2XX 成功
    OK(200, "success"),

    //4xx 客户端错误(请求存在错误)
    BAD_REQUEST(400, "Bad Request"),
    UNAUTHORIZED(401, "Unauthorized"),
    PAYMENT_REQUIRED(402, "Payment Required"),
    FORBIDDEN(403, "Forbidden"),
    NOT_FOUND(404, "Not Found"),
    REQUEST_TIMEOUT(408, "Request Timeout"),

    TOKEN_INVALID_OR_EXPIRED(409, "Token Invalid Or Expired"),
    LOCKED(423, "Locked"),
    TOO_EARLY(425, "Too Early"),
    TOO_MANY_REQUESTS(429, "Too Many Requests"),
    UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons"),

    NO_CLIENT_ID(460, "No clientId"),


    //5xx 服务端错误
    INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
    NOT_IMPLEMENTED(501, "Not Implemented"),
    BAD_GATEWAY(502, "Bad Gateway"),
    SERVICE_UNAVAILABLE(503, "Service Unavailable"),
    GATEWAY_TIMEOUT(504, "Gateway Timeout"),
    VERSION_NOT_SUPPORTED(505, "Version not supported"),
    INSUFFICIENT_STORAGE(507, "Insufficient Storage"),
    LOOP_DETECTED(508, "Loop Detected"),
    LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"),

    UNKNOWN_ERROR(555, "未知错误"),

    //6xx 参数级错误：表示因入参的值导致的错误
    ARGUMENT_ERROR(600, "参数错误"),
    // IllegalArgumentException
    ILLEGAL_ARGUMENT(601, "参数非法"),
    // InvalidFormatException
    INVALID_FORMAT(602, "参数格式错误"),
    // MethodArgumentNotValidException
    METHOD_ARGUMENT_NOT_VALID(603, "参数验证不通过"),
    // XSS ILLEGAL_CHARACTERS
    ILLEGAL_CHARACTERS(604, "非法字符"),

    // 7XX 数据级错误：表示数据结果错误
    NO_ERROR(700, "查询数据不存在错误"),
    NO_DATA(701, "数据不存在"),
    NO_USER(702, "用户不存在"),
    NO_TENANT(703, "租户不存在"),
    NO_USER_ID(704, "用户ID不存在"),
    NO_USER_INFO_ID(705, "用户InfoID不存在"),
    NO_ADMIN_ID(706, "管理员ID不存在"),

    // 8XX 数据库级错误：表示数据库操作错误
    SQL_ERROR(800, "DB SQL错误"),
    // DuplicateKeyException
    SQL_DUPLICATE_KEY(801, "DB数据重复"),
    // DataIntegrityViolationException
    SQL_DATA_INTEGRITY_VIOLATION(802, "DB数据不完整性"),

    //100X 认证相关：auth 相关
    AUTH_ERROR(1000, "认证错误"),
    INVALID_REQUEST(1001, "请求参数无效或缺失"),
    INVALID_CLIENT(1002, "客户端认证失败"),
    INVALID_GRANT(1003, "提供的授权凭证无效"),
    UNAUTHORIZED_CLIENT(1004, "客户端没有权限使用指定的授权类型"),
    UNSUPPORTED_GRANT_TYPE(1005, "授权服务器不支持请求的授权类型"),
    INVALID_SCOPE(1006, "请求的范围无效或不支持"),
    ACCESS_DENIED(1007, "资源所有者或授权服务器拒绝了请求"),
    UNSUPPORTED_RESPONSE_TYPE(1008, "授权服务器不支持请求的响应类型"),
    GENERATE_ACCESS_TOKEN_ERROR(1009, "accessToken生成发生错误"),
    GENERATE_REFRESH_TOKEN_ERROR(1010, "refreshToken生成发生错误"),
    UNSUPPORTED_USER_DETAILS(1011, "授权服务器不支持请求的UserDetails"),

    // 根据 username，phone，openid... 没有找到账号
    WRONG_ACCOUNT(1020, "账号错误"),
    // 找到多个账号
    WRONG_ACCOUNT_ERROR(1021, "账号异常"),

    WRONG_PASSWORD_OR_USERNAME(1022, "用户名或密码错误"),
    WRONG_PASSWORD(1023, "密码错误"),

    VERIFY_CAPTCHA_EXPIRED(1031, "验证码已过期"),
    VERIFY_CAPTCHA_ERROR(1032, "验证码错误"),
    VERIFY_CAPTCHA_SEND_FREQUENTLY(1033, "验证码发送太频繁，请稍后再试"),
    VERIFY_CAPTCHA_INVALID(1034, "验证码无效或未发送"),

    WRONG_PHONE(1041, "手机号错误"),
    WRONG_OPEN_ID(1042, "OpenID错误"),

    ACCOUNT_NO_ROLE(1100, "没有可用角色"),
    ACCOUNT_IS_NOT_ENABLED(1101, "账号不可用"),
    ACCOUNT_IS_LOCKED(1102, "账号已被锁定"),
    ACCOUNT_IS_EXPIRED(1103, "账号过期"),

    //存在依赖数据
    HAS_DATA_EXIST(1200, "存在依赖数据"),

    ;


    private final Integer code;

    private final String msg;

    ResultEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }


}
